package web

import (
	"goskeleton/app/global/consts"

	"goskeleton/app/service/category/curd"

	"goskeleton/app/utils/response"

	"goskeleton/app/model/category"

	"github.com/gin-gonic/gin"
)

type ArticleCategory struct {
}

func (ac *ArticleCategory) Create(context *gin.Context) {
	parentId := context.GetFloat64(consts.ValidatorPrefix + "parent_id")
	name := context.GetString(consts.ValidatorPrefix + "name")

	if curd.CreateArticleCurdFactory().Create(parentId, name) {
		response.Success(context, consts.CurdStatusOkMsg, "")
	} else {
		response.Fail(context, consts.CurdRegisterFailCode, consts.CurdRegisterFailMsg, "")
	}
}

func (ac *ArticleCategory) List(context *gin.Context) {
	list := category.CreateArticleFactory("").List()
	if list != nil {
		response.Success(context, consts.CurdStatusOkMsg, gin.H{"data": list})
	} else {
		response.Fail(context, consts.CurdSelectFailCode, consts.CurdSelectFailMsg, "")
	}
}
